!测试集合通信接口信息
!mpifort mpi_max_broadcast.F90 -o mpi_max_brodcast
!mpirun --allow-run-as-root -np 4 -x LD_PRELOAD=/home/luosf321/tool_chain/build/libs/mpitracer/libmpitracer.so mpi_max_brodcast
program mpi_demo
    use mpi
    implicit none
    integer :: ierr, rank, num_procs
    integer :: value, max_val
    integer :: broadcast_val
    integer, parameter :: root = 0

    call MPI_INIT(ierr)
    if (ierr /= MPI_SUCCESS) then
        print *, 'MPI_INIT failed!'
        stop
    end if

    call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
    call MPI_COMM_SIZE(MPI_COMM_WORLD, num_procs, ierr)

    value = rank + 1

    print '(a, i2, a, i3)', 'Process ', rank, ' initial value = ', value
    call MPI_ALLREDUCE(value, max_val, 1, MPI_INTEGER, MPI_MAX, MPI_COMM_WORLD, ierr)
    
    if (rank == root) then
        broadcast_val = 100
    end if

    call MPI_BCAST(broadcast_val, 1, MPI_INTEGER, root, MPI_COMM_WORLD, ierr)
    call MPI_FINALIZE(ierr)
end program mpi_demo
